package com.rdc.example.view;

import com.rdc.example.bean.dto.ArticleDTO;
import com.rdc.example.bean.dto.CommentDTO;

import java.util.List;

import static com.rdc.example.view.UtilView.getUserInputString;

/**
 * @author duck
 */
public class ArticleView {
    public static void showArticle(int i, ArticleDTO dto) {
        System.out.println((i+1) + "号---------------------------");
        System.out.println("|标题："+dto.getTitle()+"\t作者："+dto.getAuthor()+"\t赞数："+dto.getLikes());
        System.out.println("|创建时间："+dto.getCreatedAt()+"\t最新评论时间："+dto.getUpdatedAt());
        System.out.println("|");
    }

    public static void showArticleAndColumn(ArticleDTO dto, List<CommentDTO> list) {
        System.out.println( "文章内容------------------------");
        System.out.println("|标题："+dto.getTitle()+"\t作者："+dto.getAuthor()+"\t赞数："+dto.getLikes());
        System.out.println("|内容："+dto.getContent());
        System.out.println("|创建时间："+dto.getCreatedAt()+"\t最新评论时间："+dto.getUpdatedAt());
        System.out.println("评论区-------------------------");
        if (list.isEmpty()){
            System.out.println("暂无评论，空空如也");
            return;
        }
        for (int i=0;i<list.size();i++) {
            System.out.println((i+1) + "号 "+list.get(i).getUserName() + ": "+list.get(i).getContent() + "\t\t评论数时间: "+list.get(i).getCreatedAt()+"\t赞数："+list.get(i).getLikes());
        }
    }

    public static void insertArticle(ArticleDTO articleDTO) {
        String title= getUserInputString("请输入标题： ");
        if (title.isEmpty()){
            System.out.println("标题不可为空！");
            return;
        }
        String content= getUserInputString("请输入内容； ");
        if (content.isEmpty()){
            System.out.println("内容不可为空！");
            return;
        }
        articleDTO.setTitle(title);
        articleDTO.setContent(content);
    }

    public static String getInputString(){
        return UtilView.getUserInputString("请输入文章标题关键词：");
    }








}
